package com.zhong.thesimpleconnection.model;

import android.os.Environment;

import java.io.File;

/**
 * Created by 俊峰 on 2017/5/16.
 * 用于获取存储文件的路径
 */

public class FileSavePath {
    public static int TYPE_GETSAVE_PRIVATEKEY_PATH = 1;
    public static int TYPE_GETSAVE_PUBLICKEY_PATH = 2;

    /**
     * 用于获取存储Key的文件
     * @param Type：Type = 1 表示返回存储privateKey（私钥）的文件；
     *               Type = 2 表示返回存储publicKey（公钥）的文件
     * @return
     */
    public static File getSaveKeyPath(int Type){
        File ret = null;
        File secret = new File(Environment.getExternalStorageDirectory(), "MyCryptSecret");
        if (secret.exists()) {
            switch (Type) {
                case 1:
                    File privateKeyFile = new File(secret, "privateKey.txt");
                    if (privateKeyFile.exists()) {
                        ret = privateKeyFile;
                    }
                    break;
                case 2:
                    File publicKey = new File(secret, "publicKey.txt");
                    if (publicKey.exists()) {
                        ret = publicKey;
                    }
                    break;
                default:
                    break;
            }
        }
        return ret;
    }
}
